package Io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/*
        FileOutPutStream(String filename)
         FileOutPutStream(File file)
        构造器是覆盖模式,写入内容后，再次写入会自动清除上次的内容
         FileOutPutStream(File file,boolean append)此模式不会
 */
public class WriteStringDemo {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("./Stringdemo.txt");
        FileOutputStream fos1 = new FileOutputStream("./Stringdemo.txt",true);
        String line = "浪子回头";
        //转换成UTF-8国际标准编码
        //String提供了将字符串按照指定字符集转换为一组字节的方法:
        //byte[] getBytes(Charset cs)
        byte [] b = line.getBytes(StandardCharsets.UTF_8);
        fos1.write("你好".getBytes(StandardCharsets.UTF_8));
        fos.write(b);
        fos.close();
        fos1.close();
    }
}
